home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / joy32 / joy32.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-07-28  |  10.5 KB  |  331 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Joystick Demo 32-bit"
  5.    ClientHeight    =   2490
  6.    ClientLeft      =   1575
  7.    ClientTop       =   2400
  8.    ClientWidth     =   8175
  9.    Height          =   2895
  10.    Icon            =   "joy32.frx":0000
  11.    Left            =   1515
  12.    LinkTopic       =   "Form1"
  13.    MaxButton       =   0   'False
  14.    MinButton       =   0   'False
  15.    ScaleHeight     =   2490
  16.    ScaleWidth      =   8175
  17.    Top             =   2055
  18.    Width           =   8295
  19.    Begin VB.Timer Timer1 
  20.       Interval        =   55
  21.       Left            =   7920
  22.       Top             =   60
  23.    End
  24.    Begin VB.CommandButton Command1 
  25.       Caption         =   "&Exit"
  26.       Height          =   315
  27.       Left            =   6840
  28.       TabIndex        =   11
  29.       Top             =   2100
  30.       Width           =   675
  31.    End
  32.    Begin VB.PictureBox PicBackground 
  33.       BackColor       =   &H00C0C0C0&
  34.       Height          =   2475
  35.       Left            =   0
  36.       ScaleHeight     =   2415
  37.       ScaleWidth      =   6075
  38.       TabIndex        =   0
  39.       Top             =   0
  40.       Width           =   6135
  41.       Begin VB.Image imgCursor 
  42.          Height          =   480
  43.          Index           =   3
  44.          Left            =   5520
  45.          Picture         =   "joy32.frx":0442
  46.          Top             =   1080
  47.          Visible         =   0   'False
  48.          Width           =   480
  49.       End
  50.       Begin VB.Image imgCursor 
  51.          Height          =   480
  52.          Index           =   2
  53.          Left            =   4920
  54.          Picture         =   "joy32.frx":0884
  55.          Top             =   1080
  56.          Visible         =   0   'False
  57.          Width           =   480
  58.       End
  59.       Begin VB.Image imgCursor 
  60.          Height          =   480
  61.          Index           =   1
  62.          Left            =   5520
  63.          Picture         =   "joy32.frx":0CC6
  64.          Top             =   480
  65.          Visible         =   0   'False
  66.          Width           =   480
  67.       End
  68.       Begin VB.Image imgCursor 
  69.          Height          =   480
  70.          Index           =   0
  71.          Left            =   4920
  72.          Picture         =   "joy32.frx":1108
  73.          Top             =   480
  74.          Visible         =   0   'False
  75.          Width           =   480
  76.       End
  77.       Begin VB.Image imgJoyCursor 
  78.          Height          =   480
  79.          Left            =   2040
  80.          Picture         =   "joy32.frx":154A
  81.          Top             =   660
  82.          Width           =   480
  83.       End
  84.       Begin VB.Label lblButton 
  85.          Alignment       =   2  'Center
  86.          BackColor       =   &H00008000&
  87.          BorderStyle     =   1  'Fixed Single
  88.          Caption         =   "Button 4"
  89.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  90.             Name            =   "MS Sans Serif"
  91.             Size            =   8.25
  92.             Charset         =   0
  93.             Weight          =   700
  94.             Underline       =   0   'False
  95.             Italic          =   0   'False
  96.             Strikethrough   =   0   'False
  97.          EndProperty
  98.          ForeColor       =   &H00000080&
  99.          Height          =   315
  100.          Index           =   3
  101.          Left            =   4680
  102.          TabIndex        =   4
  103.          Top             =   2040
  104.          Width           =   1335
  105.       End
  106.       Begin VB.Label lblButton 
  107.          Alignment       =   2  'Center
  108.          BackColor       =   &H00008000&
  109.          BorderStyle     =   1  'Fixed Single
  110.          Caption         =   "Button 3"
  111.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  112.             Name            =   "MS Sans Serif"
  113.             Size            =   8.25
  114.             Charset         =   0
  115.             Weight          =   700
  116.             Underline       =   0   'False
  117.             Italic          =   0   'False
  118.             Strikethrough   =   0   'False
  119.          EndProperty
  120.          ForeColor       =   &H00000080&
  121.          Height          =   315
  122.          Index           =   2
  123.          Left            =   60
  124.          TabIndex        =   3
  125.          Top             =   2040
  126.          Width           =   1335
  127.       End
  128.       Begin VB.Label lblButton 
  129.          Alignment       =   2  'Center
  130.          BackColor       =   &H00008000&
  131.          BorderStyle     =   1  'Fixed Single
  132.          Caption         =   "Button 2"
  133.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  134.             Name            =   "MS Sans Serif"
  135.             Size            =   8.25
  136.             Charset         =   0
  137.             Weight          =   700
  138.             Underline       =   0   'False
  139.             Italic          =   0   'False
  140.             Strikethrough   =   0   'False
  141.          EndProperty
  142.          ForeColor       =   &H00000080&
  143.          Height          =   315
  144.          Index           =   1
  145.          Left            =   4680
  146.          TabIndex        =   2
  147.          Top             =   60
  148.          Width           =   1335
  149.       End
  150.       Begin VB.Label lblButton 
  151.          Alignment       =   2  'Center
  152.          BackColor       =   &H00008000&
  153.          BorderStyle     =   1  'Fixed Single
  154.          Caption         =   "Button 1"
  155.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  156.             Name            =   "MS Sans Serif"
  157.             Size            =   8.25
  158.             Charset         =   0
  159.             Weight          =   700
  160.             Underline       =   0   'False
  161.             Italic          =   0   'False
  162.             Strikethrough   =   0   'False
  163.          EndProperty
  164.          ForeColor       =   &H00000080&
  165.          Height          =   315
  166.          Index           =   0
  167.          Left            =   60
  168.          TabIndex        =   1
  169.          Top             =   60
  170.          Width           =   1335
  171.       End
  172.    End
  173.    Begin VB.Label lblMinY 
  174.       Caption         =   "0"
  175.       ForeColor       =   &H000000FF&
  176.       Height          =   195
  177.       Left            =   6960
  178.       TabIndex        =   17
  179.       Top             =   1740
  180.       Width           =   675
  181.    End
  182.    Begin VB.Label lblMaxY 
  183.       Caption         =   "0"
  184.       ForeColor       =   &H000000FF&
  185.       Height          =   195
  186.       Left            =   6960
  187.       TabIndex        =   16
  188.       Top             =   1440
  189.       Width           =   675
  190.    End
  191.    Begin VB.Label lblMinX 
  192.       Caption         =   "0"
  193.       ForeColor       =   &H000000FF&
  194.       Height          =   195
  195.       Left            =   6960
  196.       TabIndex        =   15
  197.       Top             =   1140
  198.       Width           =   675
  199.    End
  200.    Begin VB.Label lblMaxX 
  201.       Caption         =   "0"
  202.       ForeColor       =   &H000000FF&
  203.       Height          =   195
  204.       Left            =   6960
  205.       TabIndex        =   14
  206.       Top             =   840
  207.       Width           =   675
  208.    End
  209.    Begin VB.Label lblY 
  210.       Caption         =   "0"
  211.       ForeColor       =   &H000000FF&
  212.       Height          =   195
  213.       Left            =   6960
  214.       TabIndex        =   13
  215.       Top             =   480
  216.       Width           =   675
  217.    End
  218.    Begin VB.Label lblX 
  219.       Caption         =   "0"
  220.       ForeColor       =   &H000000FF&
  221.       Height          =   195
  222.       Left            =   6960
  223.       TabIndex        =   12
  224.       Top             =   180
  225.       Width           =   675
  226.    End
  227.    Begin VB.Label Label2 
  228.       Caption         =   "MinY:"
  229.       Height          =   195
  230.       Index           =   5
  231.       Left            =   6360
  232.       TabIndex        =   10
  233.       Top             =   1740
  234.       Width           =   495
  235.    End
  236.    Begin VB.Label Label2 
  237.       Caption         =   "MaxY:"
  238.       Height          =   195
  239.       Index           =   4
  240.       Left            =   6360
  241.       TabIndex        =   9
  242.       Top             =   1440
  243.       Width           =   495
  244.    End
  245.    Begin VB.Label Label2 
  246.       Caption         =   "MinX:"
  247.       Height          =   195
  248.       Index           =   3
  249.       Left            =   6360
  250.       TabIndex        =   8
  251.       Top             =   1140
  252.       Width           =   495
  253.    End
  254.    Begin VB.Label Label2 
  255.       Caption         =   "MaxX:"
  256.       Height          =   195
  257.       Index           =   2
  258.       Left            =   6360
  259.       TabIndex        =   7
  260.       Top             =   840
  261.       Width           =   495
  262.    End
  263.    Begin VB.Label Label2 
  264.       Caption         =   "Y:"
  265.       Height          =   195
  266.       Index           =   1
  267.       Left            =   6360
  268.       TabIndex        =   6
  269.       Top             =   480
  270.       Width           =   495
  271.    End
  272.    Begin VB.Label Label2 
  273.       Caption         =   "X:"
  274.       Height          =   195
  275.       Index           =   0
  276.       Left            =   6360
  277.       TabIndex        =   5
  278.       Top             =   180
  279.       Width           =   495
  280.    End
  281. Attribute VB_Name = "Form1"
  282. Attribute VB_Creatable = False
  283. Attribute VB_Exposed = False
  284. Option Explicit
  285. Dim JoyInfo As tJoyInfo
  286. Dim RangeWidth As Integer
  287. Dim RangeHeight As Integer
  288. ' Label Off Colors.
  289. Const DARKGREEN = &H8000&
  290. Const DARKRED = &H80&
  291. ' Label On Colors.
  292. Const BRIGHTGREEN = &HFF00&
  293. Const BRIGHTRED = &HFF&
  294. Private Sub Command1_Click()
  295. Unload Me
  296. End Sub
  297. Private Sub Form_Load()
  298. 'Center the form on the screen.
  299. Me.Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
  300. ' Set the range for the little on-screen joystick cursor.
  301. RangeWidth = PicBackground.ScaleWidth - imgJoyCursor.Width
  302. RangeHeight = PicBackground.ScaleHeight - imgJoyCursor.Height
  303. End Sub
  304. Private Sub Timer1_Timer()
  305. Dim rc As Integer
  306. Dim i As Integer
  307. rc = GetJoystickPos(JOYSTICK1, JoyInfo)
  308. If rc = 0 Then
  309.     imgJoyCursor.Left = RangeWidth * ((JoyInfo.X - JoyCaps.Xmin) / (JoyCaps.Xmax - JoyCaps.Xmin))
  310.     imgJoyCursor.Top = RangeHeight * ((JoyInfo.Y - JoyCaps.Ymin) / (JoyCaps.Ymax - JoyCaps.Ymin))
  311.     lblX = JoyInfo.X
  312.     lblY = JoyInfo.Y
  313.     lblMaxX = JoyCaps.Xmax
  314.     lblMinX = JoyCaps.Xmin
  315.     lblMaxY = JoyCaps.Ymax
  316.     lblMinY = JoyCaps.Ymin
  317.     For i = 0 To 3
  318.         If JoyInfo.ButtonDown(i + 1) Then
  319.             imgJoyCursor = imgCursor(i)
  320.             If lblButton(i).BackColor <> BRIGHTGREEN Then
  321.                 lblButton(i).BackColor = BRIGHTGREEN
  322.                 lblButton(i).ForeColor = BRIGHTRED
  323.             End If
  324.         Else
  325.                 lblButton(i).BackColor = DARKGREEN
  326.                 lblButton(i).ForeColor = DARKRED
  327.         End If
  328.     Next
  329. End If
  330. End Sub
  331.